/// @tags:
#include <cstdio>
#include <functional>
#include <iostream>
#include <numeric>

using std::cin, std::cout, std::endl;

namespace BlueQuantum {

constexpr int maxn = 1e5 + 5;

int a[maxn], b[maxn];

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

void solve() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  if (n == 1 || n == 2) {
    cout << "YES\n";
  } else {
    b[1] = a[1];
    for (int i = 2; i <= n; ++i) {
      b[i] = a[i - 1] * a[i] / gcd(a[i - 1], a[i]);
      if (gcd(b[i], b[i - 1]) != a[i - 1]) {
        cout << "NO\n";
        return;
      }
    }
    b[n + 1] = a[n];
    if (gcd(b[n + 1], b[n]) != a[n]) {
      cout << "NO\n";
      return;
    }
    cout << "YES\n";
  }
  return;
}

int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

}  // namespace BlueQuantum

int main() {
#ifndef ONLINE_JUDGE
#ifdef LOCAL
  freopen("/tmp/CodeTmp/testdata.in", "r", stdin);
  freopen("/tmp/CodeTmp/testdata.out", "w", stdout);
#else
  freopen("B. Playing with GCD.in", "r", stdin);
  freopen("B. Playing with GCD.out", "w", stdout);
#endif
#endif

  std::ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  return BlueQuantum::main();
}
